<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <h1>注册</h1>
        <p>
            用户名: <input type="text" id="username">
        </p>
        <p>
            密 &nbsp; 码: <input type="text" id="pwd">
        </p>
        <p style="margin-top: 1rem;">
            <button id="Registration">注册</button>
        </p>


    </div>

</body>
<script>
    window.onload = function () {
        Registration.onclick = fun
    }
    function fun() {
        let username = document.getElementById('username').value
            pwd = document.getElementById('pwd').value
        if (username == "" || pwd == "") {
            alert('注册失败')
        } else {
            let username = document.getElementById('username').value
            pwd = document.getElementById('pwd').value
            let xhr = new XMLHttpRequest()
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    let res = JSON.parse(xhr.responseText)
                    console.log(res);
                }
            }
            xhr.open('post', 'https://liu.zzgoodqc.cn/register', true)
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
            xhr.send('username=' + username + '&password=' + pwd + '&email=13241')
            //跳转页面
            location.replace("http://127.0.0.1:5501/3dd/login/%E7%99%BB%E5%BD%95.html");
        }
    }

</script>
<style>
    * {
        padding: 0;
        margin: 0;
    }

    body {
        width: 100%;
        height: 49rem;
        background: url('http://pic.bizhi360.com/bbpic/53/11153.jpg') no-repeat;
        background-size: 100% 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .box {
        width: 30%;
        height: 20rem;
        border: 1px solid #fff;
        color: #fff;
        background-color: #000;
        z-index: 5;
        opacity: 0.5;

        text-align: center;
        /* line-height: 1rem; */

    }

    h1{
        width: 100%;
        height: 3rem;
        margin-top: 1rem;
    }
    .box p {
        width: 100%;
        height: 4rem;
        color: #fff;
        font-size: 1.2rem;
        line-height: 4rem;
    }

    .box input {
        width: 12rem;
        height: 1.8rem;
    }

    button {
        width: 8rem;
        height: 2.5rem;
        color: #fff;
        font-size: 1.5rem;
        background-color: chartreuse;
        border: none;

    }
</style>

</html>